import { zhCN, dateZhCN, enUS, dateEnUS, type NLocale, type NDateLocale } from "naive-ui"

/**
 * 语言设置
 *
 * @param defaultValue 默认值
 */
export function useLocal(defaultValue: string) {
    const supportLangurge = [
        {
            label: "中文",
            key: "zh-cn"
        },
        {
            label: "英文",
            key: "en-us"
        }
    ]

    const supportLocal: Recordable<{ local: NLocale; dateLocal: NDateLocale }> = {
        "zh-cn": {
            local: zhCN,
            dateLocal: dateZhCN
        },
        "en-us": {
            local: enUS,
            dateLocal: dateEnUS
        }
    }

    const local = ref<string>(defaultValue)

    function setLocal(newLocal: string) {
        local.value = newLocal
    }

    const localInfo = computed(() => supportLocal[local.value])

    return { supportLangurge, local, setLocal, localInfo }
}
